<html>
<head><meta charset="utf-8"><title>Writing backends · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html">Writing backends</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226675547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226675547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark R. Tuttle <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226675547">(Feb 17 2021 at 15:45)</a>:</h4>
<p>What is the recommended route to writing a rustc backend?  We are writing a verification tool and compiling from mir to our tool.</p>
<ul>
<li>I've read the <a href="https://rustc-dev-guide.rust-lang.org/">rustc developer's guide</a> (I see the "<a href="https://rustc-dev-guide.rust-lang.org/part-5-intro.html">MIR to Binaries</a>" chapter).</li>
<li>I've read some code from the llvm backend, and I'm aware of the cranelift backend.</li>
<li>I'm aware of other verification projects like <a href="https://www.pm.inf.ethz.ch/research/prusti.html">Prusti</a> and <a href="https://crux.galois.com/">Curx MIR</a> that do the same kind of thing.</li>
</ul>
<p>Are there other resources or guides for getting started?</p>



<a name="226678309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226678309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226678309">(Feb 17 2021 at 16:00)</a>:</h4>
<p>I don't think there's any tutorials. The closest thing in-tree is rustdoc, which outputs HTML instead of object code, but rustdoc also mangles large parts of the query system (<a href="https://github.com/rust-lang/rust/pull/73566">https://github.com/rust-lang/rust/pull/73566</a>). Looking at Prusti might be a good starting place.</p>



<a name="226678753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226678753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226678753">(Feb 17 2021 at 16:02)</a>:</h4>
<p>There's also <a href="https://github.com/robinmoussu/cargo-callgraph">https://github.com/robinmoussu/cargo-callgraph</a> which is a fork of Rustdoc that works on MIR and builds out-of-tree</p>



<a name="226679265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226679265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226679265">(Feb 17 2021 at 16:03)</a>:</h4>
<p>I have <a href="https://github.com/bjorn3/rustc_codegen_cranelift/issues/647">https://github.com/bjorn3/rustc_codegen_cranelift/issues/647</a> with a bunch of advice, but I never got around actually writing a guide or something like that.</p>



<a name="226679933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226679933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226679933">(Feb 17 2021 at 16:06)</a>:</h4>
<p>Oh oh this is specifically about <em>codegen</em> backends. Yes, cg_clif is a better example than rustdoc, then.</p>



<a name="226680133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226680133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226680133">(Feb 17 2021 at 16:07)</a>:</h4>
<p>By the way are you using <code>-Zmir-opt-level=0</code>? That disables optimizations that may hide UB.</p>



<a name="226760414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20backends/near/226760414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark R. Tuttle <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20backends.html#226760414">(Feb 18 2021 at 03:27)</a>:</h4>
<p>Thanks for these leads!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>